package com.jobpass.controller;

import com.jobpass.common.data.ResultData;
import com.jobpass.common.model.Pullresume;
import com.jobpass.common.service.PullresumeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @Author: Qning
 * @Description: 投递简历
 * @Date: 2020/7/20 17:44
 * @PackageName: com.jobpass.controller
 * @ClassName: PullresumeController
 */
@Api(tags="投递简历Controller")
@RestController
@RequestMapping("student")
public class PullresumeController {
    @Resource
    private PullresumeService pullresumeService;

    //当前学生id
    private static final long studentId = 1;
    //当前公司id
    private static final long recruitId = 1;

    /**
     *
     * @Author: Qning
     * @Description: 投递简历
     * @Date: 19:28 2020/7/20
     * @param
     * @return: com.jobpass.common.data.ResultData
     */
    @ApiOperation(value="投递简历")
    @GetMapping("/pullresume")
    public ResultData pullresume(){
        Pullresume bySidAndRid = pullresumeService.findBySidAndRid(studentId, recruitId);
        if (bySidAndRid != null) {
            //已经投过简历
            return ResultData.fail("1","您已在该公司投过简历");
        }
        Pullresume pullResume = new Pullresume()
                .setStudentId(studentId)
                .setRecruitId(recruitId);

        boolean b = pullresumeService.save(pullResume);

        if (b) {
            return ResultData.fail("0","投递成功");
        }
        //投递失败
        return ResultData.fail("1","投递失败");
    }
}
